home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / VirtualFile / VirtualFile.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  3.1 KB  |  143 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        VirtualFile.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __VIRTUALFILE__
  15. #include "VirtualFile.h"
  16. #endif
  17.  
  18. #ifndef __DEBUGGINGGEAR__
  19. #include "DebuggingGear.h"
  20. #endif
  21.  
  22. #pragma segment VirtualFile
  23.  
  24. ImplementList(TVirtualFile,TVirtualFileList,true);
  25.  
  26. ostream& TVirtualFile::operator >> ( ostream& s ) const
  27. {
  28.     TAbstractFile::operator >> ( s );
  29.     return s << ", count " << fReferenceCount;
  30. }
  31.  
  32. //--------------------------------------------------------------------------------
  33.  
  34. TVirtualFile::TVirtualFile() :
  35.     TAbstractFile (),
  36.     fUserRef ( 0 ),
  37.     fReferenceCount ( 0 ),
  38.     fAutoDispose ( true )
  39. {
  40.     UpdateUsage();
  41. }
  42.  
  43. //--------------------------------------------------------------------------------
  44.  
  45. TVirtualFile::TVirtualFile( const TVirtualFile& that ):
  46.     TAbstractFile ( that ),
  47.     fUserRef ( 0 ),
  48.     fReferenceCount ( 0 ),
  49.     fAutoDispose ( true )
  50. {
  51.     UpdateUsage();
  52. }
  53.  
  54. //--------------------------------------------------------------------------------
  55.  
  56. TVirtualFile&
  57. TVirtualFile::operator = ( const TVirtualFile& that )
  58. {
  59.     TAbstractFile::operator = ( that );
  60.     return *this;
  61. }
  62.  
  63. //--------------------------------------------------------------------------------
  64.  
  65. TVirtualFile::~TVirtualFile()             // destructor
  66. {
  67. }
  68.  
  69. //--------------------------------------------------------------------------------
  70.  
  71. void TVirtualFile::SetUserRef(long ref)
  72. {
  73.     fUserRef = ref;
  74. }
  75.  
  76. //--------------------------------------------------------------------------------
  77.  
  78. long TVirtualFile::GetUserRef() const {
  79.     return fUserRef;
  80. }
  81.  
  82. //--------------------------------------------------------------------------------
  83. // Increment the count of references to this object
  84.  
  85. void TVirtualFile::RegisterReference()
  86. {
  87.     fReferenceCount++;
  88. }
  89.  
  90. //--------------------------------------------------------------------------------
  91. // Decrement the count of references to this object
  92. // If the count reaches zero and fAutoDispose is true
  93. // Then the object deletes itself
  94.  
  95. void TVirtualFile::UnregisterReference()
  96. {
  97.     fReferenceCount--;
  98.     
  99.     if (fReferenceCount<=0)
  100.     {
  101.         if (fAutoDispose) {
  102. #if debug
  103.             if (steveFlag.Flag(18)) {
  104.                 steve << "TVirtualFile::UnregisterReference, fRefCount decremented to 0; deleting file." << endl;
  105.             }
  106. #endif
  107.             delete this;
  108.         } else {
  109.             fReferenceCount=0;
  110.         }
  111.     }
  112. }
  113.  
  114. //--------------------------------------------------------------------------------
  115.  
  116. Boolean TVirtualFile::GetAutoDispose() const
  117. {
  118.     return fAutoDispose;
  119. }
  120.  
  121. //--------------------------------------------------------------------------------
  122.  
  123. void TVirtualFile::SetAutoDispose(Boolean doDispose)
  124. {
  125.     fAutoDispose = doDispose;
  126. }
  127.  
  128. //--------------------------------------------------------------------------------
  129.  
  130. void TVirtualFile::UpdateUsage()
  131. {
  132.     fLastUsed = TickCount ();
  133. }
  134.  
  135. //--------------------------------------------------------------------------------
  136.  
  137. long TVirtualFile::LastUsed() const
  138. {
  139.     return fLastUsed;
  140. }
  141.  
  142. /***********************************|****************************************/
  143.